package com.tchepannou.limbe.validation;

import java.lang.reflect.Field;
import java.util.Calendar;
import java.util.Date;

/**
 * User: herve
 * Date: 14-01-12 12:14 PM
 */
public class PastValidator extends AbstractValidator
{
    @Override
    public boolean validate(Object bean, Field field)
    {
        Object value = getValue(bean, field);

        if (value == null)
        {
            return true;
        }
        else if (value instanceof Date)
        {
            return ((Date)value).getTime() <= System.currentTimeMillis();
        }
        else if (value instanceof Calendar)
        {
            return ((Calendar)value).getTime().getTime() <= System.currentTimeMillis();
        }
        else
        {
            return false;
        }
    }

    @Override
    public boolean validate(Object bean)
    {
        return false;
    }
}
